package com.ddone.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
 * @author ddone
 * @date 2024/4/1-17:42
 */
@RestController
public class RedisDemoController {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * API 参考 https://blog.csdn.net/lydms/article/details/105224210
     * @return
     */

    @RequestMapping("/hello")
    public String helloRedis(){
        System.out.println(redisTemplate);
        redisTemplate.boundValueOps("ookk").set("ookk~~~");
        Set<String> keys = redisTemplate.keys("*");
        // redisTemplate.delete("")
        Optional.ofNullable(keys).ifPresent(System.out::println);

        redisTemplate.delete("ookk");
        Optional.ofNullable(keys).ifPresent(System.out::println);
        List<Object> li = redisTemplate.boundListOps("list1").range(0, 10);
        Optional.ofNullable(li).ifPresent(System.out::println);
        return "HelloRedis~~~";
    }
}
